package com.whmskj.xjlhsc.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaIgnore;
import com.whmskj.xjlhsc.controller.fo.TaskStatisticsFo;
import com.whmskj.xjlhsc.controller.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import com.whmskj.xjlhsc.entity.WbRecord;
import com.whmskj.xjlhsc.service.WbRecordService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.GetMapping;
import java.util.List;

/**
 * 维保任务流转记录表
 *
 * @author lk
 * @since 2025-06-16 13:31:13
 */
@RestController
@RequestMapping("/api/wbRecord")
@Api(tags = "维保任务记录接口", value = "WbRecordController")
@SaIgnore
public class WbRecordController {

    @Autowired
    private WbRecordService wbRecordService;

    /**
     * 分页查询
     *
     * @param params
     * @return
     */
    @GetMapping("/findPage")
    public Result findPage( WbRecord params) {
        Page<WbRecord> result = wbRecordService.findPage(params);
        return Result.success(result);
    }
    /**
     * 列表查询
     *
     * @param params
     * @return
     */
    @PostMapping("/findList")
    public ResponseEntity<List<WbRecord>> findList(@RequestBody WbRecord params) {
        List<WbRecord> result = wbRecordService.findList(params);
        return ResponseEntity.ok(result);
    }

    /**
     * 查询
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseEntity<WbRecord> findById(@PathVariable("id") Long id) {
        WbRecord wbRecord = wbRecordService.findById(id);
        return ResponseEntity.ok(wbRecord);
    }

    /**
     * 新增
     *
     * @param wbRecord
     * @return
     */
    @PostMapping
    public ResponseEntity<Boolean> insert( @RequestBody WbRecord wbRecord) {
        boolean result = wbRecordService.insert(wbRecord);
        return ResponseEntity.ok(result);
    }

    /**
     * 修改
     *
     * @param wbRecord
     * @return
     */
    @PutMapping
    public ResponseEntity<Boolean> update( @RequestBody WbRecord wbRecord) {
        boolean result = wbRecordService.update(wbRecord);
        return ResponseEntity.ok(result);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public ResponseEntity<Integer> delete(@PathVariable("id") Long id) {
        int result = wbRecordService.delete(id);
        return ResponseEntity.ok(result);
    }

    @GetMapping("/task-statistics")
    @Operation(description = "维保任务统计", method = "GET")
    public Result taskStatistics(TaskStatisticsFo fo) {
       return Result.success(wbRecordService.taskStatistics(fo));
    }

}